var selldetail = new Vue({
    el:'#selldetail',
    //初始化数据类型
    data: {
        type:0,
        goodsType: [],
        product: [],
        selected: [],
        warn: [],
        salesVolume:[],
        appraiseNum:[],
        repertory:[],
        sellinformation:{},
        dd:{},
        //对比公司信息
        contrastInformation: [],
        ids:'',
    },
    //时间提交方法
    methods:{
        over:function(id){
            $("#"+id).css('display','block');
        },
        out:function(id){
            $("#"+id).css('display','none');
        },
        //跳转商品详情页面
        Ontouch:function(sire){
            $("#selldetail").load("http://"+window.location.host+"/home/introduction.html",function(){
                introduction.product = sire;
            });
        },
        //加入购物车
        onTouchAdd:function(sire) {
            var _this = this;
            if(_this.type==0){
                _this.$message({
                    message: '警告哦，您未登录！',
                    type: 'warning'
                });
            }else{
            if (_this.sellinformation.type == 0) {
                _this.$message({
                    message: '警告哦，该商家未入围，不能添加商品到购物车！',
                    type: 'warning'
                });
            } else {
                if(sire.install==0||sire.install==2){
                    _this.$message({
                        message: '警告哦，该商品已下架不能添加至购物车！',
                        type: 'warning'
                    });
                }else{
                    $.post("/home/order_detail/insertShopCart", {
                        "lim": JSON.stringify(sire),
                        "sell": _this.sellinformation.type,
                        "ids":_this.ids
                    }, function (data) {
                        if (data.data.shopCart == 1) {
                            _this.$message({
                                message: '恭喜你，该商品已添加至购物车',
                                type: 'success'
                            });
                        } else {
                            _this.$message({
                                message: '警告哦，商品未添加至购物车',
                                type: 'warning'
                            });
                        }
                    });
                }

            }
            }
        },
        onAddDataBefore:function (mixVal) {
            debugger
            var _this=this;
            for (var l = 0; l < _this.contrastInformation.length; l++) {
                if(l==0){
                    _this.ids=_this.contrastInformation[l].id;
                }else{
                    _this.ids=_this.ids+ ","+ _this.contrastInformation[l].id;
                }
            }
            _this.onTouchAdd(mixVal);
            _this.on_hideClick();
            _this.on_shClick();

        },
        //商品对比
        on_showClick: function (sire) {
            var _this = this;
            debugger
            var ID = sire.id;
            var T = true;
            var type = '';
            if (_this.contrastInformation != null) {
                for (var i = 0; i < _this.contrastInformation.length; i++) {
                    if (_this.contrastInformation[i].id == ID) {
                        _this.contrastInformation.splice(i, 1);
                        T = false;
                        sessionStorage.contrastInformation = JSON.stringify(_this.contrastInformation);
                    }
                    type = _this.contrastInformation[i].category;
                }
            }
            if (T) {
                if (_this.contrastInformation != null) {
                    if (_this.contrastInformation.length == 5) {
                        _this.$notify({
                            message: "请注意，最多选5个商品。",
                            type: 'error'
                        });
                        return;
                    } else {

                        if ((_this.contrastInformation.length > 0) && (type != sire.category)) {
                            _this.$notify({
                                message: "请注意，不同类型商品不允许比价。",
                                type: 'error'
                            });
                            return;
                        } else {
                            _this.contrastInformation.push(sire);
                            sessionStorage.contrastInformation = JSON.stringify(_this.contrastInformation);
                        }
                    }
                    $("#contrast").show();
                }else{
                    _this.contrastInformation.push(sire);
                    sessionStorage.contrastInformation = JSON.stringify(_this.contrastInformation);
                }
            }
        },

        //模态框
        on_shClick: function () {
            debugger
            $("#dddddd").css('display','block');
        },//对比弹出框的取消事件
        on_hideClick: function () {
            var _this = this;
            _this.contrastInformation = [];
            $(".close").click();
            $(".modal-backdrop.fade.in").remove();
            $(".on_show").removeAttr("checked");//取消
            $("#contrast").hide();
            // sessionStorage.clear();
            sessionStorage.contrastInformation=_this.contrastInformation;
        },
    },
    //页面加载完成后执行此方法
    created :function(){
        var _this = this;
        var goodsTypeList = [/*{name: "定点服务", href: "#"},*/
            {name: "询价表", href: "../home/offers.html"},
            {name: "报价单", href: "../home/quotation.html"},
           /* {name: "在线询价", href: "../home/bidding.html"},*/
        ];
        _this.goodsType = goodsTypeList;
        //查看用户是否已经登录
        $.post("/home/dataCache/selectDataCache", "", function (data) {
            if(data.code == 200){
                _this.type = 1
            }

        });
        //初始化销量
        var salesVolumeShow = [
            {salesVolumeName:"月销量",salesVolumeNum:"1015"},
            {salesVolumeName:"累计销量",salesVolumeNum:"6015"}
        ];
        _this.salesVolume = salesVolumeShow;
        //初始化评价
        var appraiseNumShow = [
            {appraiseNumName:"累计评价",appraiseNumS:"640"}
        ];
        _this.appraiseNum = appraiseNumShow;
        //初始化库存
        var repertoryShow = [
            {repertoryName:"库存",repertoryNum:"1000"}
        ];
        _this.repertory = repertoryShow;
        //对比数据弹框
        debugger
        var sessiones= sessionStorage.contrastInformation;
        if(sessiones==""||sessiones==null){

        }else{
            _this.contrastInformation = JSON.parse(sessiones);
            if (_this.contrastInformation !=null && _this.contrastInformation !='') {
                if (_this.contrastInformation.length > 0) {
                    $("#contrast").show();
                }
            }
        }
    },
});